<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">

<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />

<title>修改内容</title>
</head>
<body>
<div class="pd-20">
	<form action="/baby/imgInfos/updateInformation" method="post" class="form form-horizontal form-ueditor" id="form"  enctype="multipart/form-data">
		<div class="row cl">
			<label class="form-label col-1"><span class="c-red">*</span>分类名称：</label>
			<div class="formControls col-2"> <span class="select-box">
				<select name="type" id="type" class="select">
				<option value="1">赴美生子 套餐</option>
					<option value="5">孕前服务 医生</option>
					<option value="6">美国服务 产检服务</option>
					<option value="7">美国服务 办证服务</option>
					<option value="8">回国服务 回国指导</option>	
					<option value="9">回国服务 美宝教育基金</option>	
					<option value="10">回国服务 入学指南</option>
					<option value="11">海外医疗 美国试管</option>
					<option value="12">海外医疗 泰国试管</option>				
					<option value="13">美国服务 儿童摄影</option>
					<option value="14">回国服务 换证旅游</option>		
					<option value="15">我们的团队_关于圣嘉尔</option>	
				</select>
				</span> </div>
		</div>

		<div class="row cl">
			<label class="form-label col-1"><span class="c-red">*</span>标题内容：</label>
			<div class="formControls col-3">
				<input type="text" class="input-text" value="" placeholder="" id="title" name="title">
        <input type="hidden" class="input-text" value="" placeholder="" id="titleid" name="sid">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-1">信息内容：</label>
			<div class="formControls col-10"> 
				<script id="editor" type="text/plain" style="width:100%;height:600px;" name="details"></script> 
			</div>
		</div>
		
		<div class="row cl">
    	  <label class="form-label col-1">已有图片:</label>
        <div class="formControls col-8">
        <div class="portfoliobox" id="str">
     
        </div>
        </div>
    </div>

    <style type="text/css">
      #view{}
      #view{} .imgbox{float:left;position:relative;width:100px;height: 100px;margin-left: 10px;margin-top: 10px;
      padding:5px;border:solid 1px red;border-radius: 5px;;}
      #view{} .imgbox .close{border: solid 1px red;position: absolute;top: -15px;
      width: 20px;height: 20px; display: inherit;cursor: pointer;text-align: center;background: red;color: #fff;right: -10px;z-index: 20;border-radius: 100%;}
      #view{} .imgbox input{width:100%;height: 100%;z-index: 10;}
    </style>
		<div class="row cl">
			<label class="form-label col-1">图片上传：</label>
			<div class="formControls col-10">
        <input type="file" name="file" id="file" datatype="*" nullmsg="请上传图片"  onchange="load(this)" multiple="multiple" accept="image/*" class='myfile'></input>
        <div id="view"></div>
			</div>
		</div>

		<div class="row cl">
			<div class="col-10 col-offset-1">
				<input type="submit" class="btn btn-primary radius"  name="submit" value="添 加" class="submit" />
			</div>
		</div>
	</form>
</div>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/1.9.3/layer.js"></script> 
<script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.config.js"></script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.all.min.js"> </script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script> 
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script>
<script src="js/jquery-form.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.validate.min.js" ></script>
<script type="text/javascript" src="js/messages_zh.min.js" ></script>
<script type="text/javascript" src="js/rule.js" ></script>

<script type="text/javascript">
var ue = UE.getEditor('editor');

$(document).ready(function(){
    $('#form').ajaxForm(function(data){

        //alert(data);//弹出ajax请求后的回调结果，data回调数据  onclick="sub()"
        if(data.code =="2000" ){ 
         alert(data.message); 
         console.log(data); 
         var type = $('.select').val();
         if(type == 1){
              window.location.href='child-list.html';
             }else if(type == 2){
              window.location.href='votes-list.html';
             }else if(type ==3){
              window.location.href='news-list.html';
             }else if(type ==4){
              window.location.href='insur-list.html';
             }else if(type ==5){
              window.location.href='doctor-list.html';
             }else if(type ==6){
              window.location.href = 'check-list.html';
             }else if(type ==7){
              window.location.href = 'rush-list.html';
             }else if(type ==8){
              window.location.href='advice-list.html';
             }else if(type ==9){
              window.location.href='usa2-list.html';
             }else if(type ==10){
              window.location.href = 'school-list.html';
             }else if(type ==11){
              window.location.href = 'usa3-list.html'; 
             }else if(type ==12){
              window.location.href = 'thai-list.html'; 
             }else if(type ==13){
              window.location.href = 'baby-photo-list.html'; 
             }else if(type ==14){
              window.location.href = 'passport-travel-list.html'; 
             } else if(type ==15){
              window.location.href = 'sjrl-list.html'; 
             }
         }else{  
            alert(data.message); 
            console.log(data);  
         }  
    });
});


 function getQueryString(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]); return null;
    }

  var sid = getQueryString("sid");

  //请求数据
  $.ajax({  
    url:'/baby/imgInfos/getImgInformation',// 跳转到 action  
    data:{sid:sid},  
    type:'post',  
    cache:false,  
    dataType:'json',  
    success:function(data) { 
        if(data.code =="2000" ){
        var data = data.data;
        console.log(data);
        $("#title").val(data.title);
        $("#titleid").val(data.sid);
  		var content = data.details;
        //判断ueditor 编辑器是否创建成功
        ue.addListener("ready", function () {
        	// editor准备好之后才可以使用
       		ue.setContent(content);
        });
        var type = data.type;
		$("#type option[value='"+type+"']").attr("selected",true);
		
		// 拼装html
        var imglist = data.imgData;
        var htmlstr='';
        if(imglist!=null){
	        for (var i=0;i<imglist.length;i++){
	        var obj = imglist[i];//获取单个数据对象
	        console.log(obj);
	        var imgsid = '\'' +obj.sid+ '\'';
	        var imgsrc = obj.realPicUrl;
	        htmlstr+= '<div class="picbox mb-10"><img src="'+imgsrc+'" class="mb-6"></div>'
	                + '<div class="btn btn-secondary radius delimg" onclick="delimg(this,\''+obj.imageUrl+'\');">删除</div>'
	       }
        }
       document.getElementById("str").innerHTML =htmlstr 

       }else{
          alert(data.message);
        }
      }, 
      error : function() {      
        alert("异常！");  
    }  
  });

//删除图片

function delimg(obj,id){
  $.ajax( {  
    url:'/baby/uploadImg/deletePic',// 跳转到 action  
    data:{key:id},  
    type:'get',  
    cache:false,  
    dataType:'json',  
    success:function(data) { 
        console.log(data);
        if(data.code =="2000" ){ 
          alert(data.message);
          window.location.reload();
        }else{
          alert(data.message);
        }
      }, 
      error : function() {      
        alert("异常！");  
    }  
  });

}
function load(file) {
  var num=1;
  if (file.files) {
  	$('.imgbox').remove()
  for (var i = 0; i < file.files.length; i++) {
  var reader = new FileReader();
  reader.readAsDataURL(file.files[i]);
  reader.onload = function(evt) {
  var imgbox=$('<div></div>');
  imgbox.addClass('imgbox');
  $('#view').append(imgbox);

  var imgs = $('<input type="image" />');
  imgs.attr('name','mum'+num);
  num++;
  imgs.appendTo(imgbox);
  imgs.attr('src', evt.target.result);
  }
}
}
}
</script>
</body>
</html>
